
function search(){
    var param = {};
    param.customName = $("[name=customName]").val();
    $("#Ztable").bootstrapTable("refresh",{query:param});
}
function queryParams(param){
    param.name = $("[name=customName]").val();
    return param;
}



function del() {
    var rows = $("#Ztable").bootstrapTable("getSelections");
    if (rows.length == 0) {
        swal({
            title: '信息提示',
            text: "请选择删除项",
            type: "warning",
            confirmButtonText: "确定"
        });
    }

    $.post("/delete",{id:rows[0].id} ,function (msg) {
        toastr.warning("信息提示",msg);
        console.log(rows[0].id);
        $("#Ztable").bootstrapTable("refresh");
    });
}

$(function(){
    $("#add").dialog({
        title:"添加用户",
        btnName:"确定",
        btnBind:function(){
            var param = $("#add form").serialize();
            $.post("add",param,function(msg){
                toastr.warning("信息提示",msg);
                $("#add").dialog("close");
                $("#Ztable").bootstrapTable("refresh");
            },'text');
        }
    });
});
function prepareAdd(){
    $("#add form")[0].reset();
    $("#add").dialog("open");
}


$(function(){
    $("#update").dialog({
        title:"修改客户信息",
        btnName:"确定",
        btnBind:function(){
            var param = $("#update form").serialize();
            $.post("/update",param,function(msg){
                toastr.warning("信息提示",msg);
                $("#update").dialog("close");
                $("#Ztable").bootstrapTable("refresh");
            },'text');
        }
    }) ;
});

function prepareUpdate(){
    var rows = $("#Ztable").bootstrapTable("getSelections");
    if(rows.length==0){
        swal({
            title:'信息提示',
            text:"请选择一项修改",
            type:"warning",
            confirmButtonText:"确定"
        });
        return;
    }
    for(var customName in rows[0]){
        $("#update").find("[name="+customName+"]").val(rows[0][customName]);
    }
    $("#update").dialog("open")
}





$(function(){
    $("#showInfo").dialog({
        title:"查看客户信息",
        btnBind:function(){
            var param = $("#showInfo form").serialize();
            $.post("/update",param,function(msg){
                toastr.warning("信息提示",msg);
                $("#showInfo").dialog("close");
                $("#showInfo").bootstrapTable("refresh");
            },'text');
        }
    }) ;
});

function sMgn(){
    var rows = $("#Ztable").bootstrapTable("getSelections");
    if(rows.length==0){
        swal({
            title:'信息提示',
            text:"请选择一项查看用户信息",
            type:"warning",
            confirmButtonText:"确定"
        });
        return;
    }
    for(var customName in rows[0]){
        $("#showInfo").find("[name="+customName+"]").val(rows[0][customName]);
    }
    $("#showInfo").dialog("open")
}

function custTypeFmt(value){
    var v;
    if(value==1)
        v="普通客户";
    else if(value==2)
        v="VIP客户";
    else if(value==3)
        v="金卡客户";
    return v;
}

function stateFmt(value){
    var v1;
    if(value==1)
        v1="正常";
    else if(value==2)
        v1="已流失";
    return v1;
}

function distrStateFmt(value){
    var v2;
    if(value==1)
        v2="未分配";
    else if(value==2)
        v2="已分配";
    return v2;
}